<?php
// +----------------------------------------------------------------------
// | EtrolPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Author:HCZ <huangchengze@etrol.com>
// +-----------------------------------------------------------------------

namespace app\common\model;

use app\common\model\Base;
/**
 * 模型基类
 */
class Role extends Base{
	protected $name = 'role';
	protected $createTime = 'createTime';
	protected $updateTime = 'updateTime';
	
	/**
	 * 角色权限
	 * @param array $value
	 * @return string
	 */
	public function setRulesAttr($value){
		$rules = [];
		foreach ($value as $key=>$item){
			$rules[] = $key;
		}
		return  implode(',', $rules);
	}
	
	/**
	 * 角色园区分布
	 * @param array $value
	 * @return string
	 */
	public function setPositionsIdAttr($value){
		$positions = [];
		foreach ($value as $key=>$item){
			$positions[] = $key;
		}
		return implode(',',$positions);
	}
	
	/**
	 * 角色园区片区
	 * @param string $value
	 * @return array
	 */
	public function setAreasIdAttr($value){
		$areas = [];
		foreach($value as $key=>$item){
			$areas[] = $key;
		}
		return implode(',',$areas);
	}

	public function users()
	{
		return $this->belongsToMany('User','roleaccess','roleId','id');
	}


}